<!-- 03VueInstance.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
	<link rel="stylesheet" href="./css/common.css"/>
    <script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
	<!-- <script src="https://cdn.bootcss.com/axios/0.19.0/axios.min.js"></script> -->
	<!-- <script src="https://cdn.bootcss.com/lodash.js/4.17.15/lodash.min.js"></script> -->
</head>
<body>
	<h2>使用事件抛出一个值</h2>
	<div id="demo">
		<div :style="{ fontSize: postFontSize + 'em' }">
			<blog-post 
				v-for="post in posts"
				v-bind:key="post.id"
				v-bind:post="post"
				v-on:enlarge-text="onEnlargeText">
			</blog-post>
		</div>
	</div>
    <script>
		Vue.component('blog-post', {
			props: ['post'],
			template: `
				<div class="blog-post">
					<h3>{{post.title}}</h3>
					<button v-on:click="$emit('enlarge-text', 0.1)">Enlarge text</button>
					<div v-html="post.content"></div>
				</div>
			`
		})
        var demo = new Vue({
			el: '#demo',
			data: {
				posts: [
					{id:1, title: 'My journey with Vue', content: '111111'},
					{id:2, title: 'Blogging with Vue', content: '2222'},
					{id:3, title: 'Why Vue is so fun', content: '33333'}
				],
				postFontSize: 1
			},
			methods: {
				onEnlargeText: function(enlargeAmount){
					this.postFontSize += enlargeAmount
				}
			}
        });
    </script>
</body>
</html>